<template>
  <div class="node-computer-container">
    <!-- 添加区域 -->
    <div class="add-area">
      <el-button v-if="!open" @click="open = !open">添加</el-button>
      <template v-else>
        <span style="display: inline-block; width: 200px">
          <el-input
            v-model="nodeNickname"
            placeholder="请输入节点昵称"
          ></el-input>
        </span>
        <span>
          <el-button type="success" @click="handleConfirmAdd">添加</el-button>
          <el-button type="info" @click="handleCancelCancel">取消</el-button>
        </span>
      </template>
    </div>
    <List />
  </div>
</template>

<script>
import * as nodeComputerApi from "@/api/nodeComputer";
import List from "./list.vue";
export default {
  components: {
    List,
  },
  data() {
    return {
      nodeNickname: "",
      open: false,
    };
  },

  methods: {
    async handleConfirmAdd() {
      const { code, data, msg } = await nodeComputerApi.create({
        nickname: this.nodeNickname,
      });
      if (code === 2000) {
        this.$message.success(msg);
        this.$router.go(0);
      } else {
        this.$message.error(msg);
      }
    },

    async handleCancelCancel() {
      (this.nodeNickname = ""), (this.open = false);
    },
  },
};
</script>

<style>
</style>